var app=getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
      aichelist:[],
      dialogShow: false,
      showOneButtonDialog: false,
      buttons: [{ text: '取消' }, { text: '确定' }],
      carid:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this.getaiche();
  },
  onShow:function(){
    
  },
  // 获取爱车列表
  getaiche:function(){
    var userid = wx.getStorageSync('userId');
    var that = this;
    var data = {
      url:"api/user/getCarList",
      data:{
        user_id:userid
      },
      success:function(e){
        console.log(e)
        that.setData({
          aichelist:e.data.data
        });
      }
    };
    app.post(data);
  },
  
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  addaiche:function(){
    wx.navigateTo({
      url: '/pages/mine/bindcar/bindcar',
    })
  },

  delcar: function (e) {
    var id = e.currentTarget.dataset.id
    this.setData({
      dialogShow: true,
      carid:id
    })
  },
  // 弹框
  tapDialogButton(e) {
    this.setData({
      dialogShow: false,
      showOneButtonDialog: false
    })
    if (e.detail.index == 0) {
      return false;
    }
    if (e.detail.index == 1) {
      
      var that = this;
      var param = {
        url: "api/user/delcar",
        data: {
          car_id: that.data.carid
        },
        success: function (e) {
          wx.showToast({
            title: e.data.msg,
            icon: 'none',
            duration: 2000
          })
          if (e.data.code == 1) {
            that.getaiche();
          }
        }
      };
      app.post(param);
    }
  },

  seedetail:function(e){
    var id = e.currentTarget.dataset.id;
    var lock = e.currentTarget.dataset.lock;
    if(lock == 1){
        return false
    }else{
      wx.navigateTo({
        url: '/pages/mine/bindcar/bindcar?id='+id,
      })
    }
  }

})